package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SlEducation;
import com.ruoyi.sl.service.ISlEducationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学历Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/education")
public class SlEducationController extends BaseController
{
    @Autowired
    private ISlEducationService slEducationService;

    /**
     * 查询学历列表
     */
    @PreAuthorize("@ss.hasPermi('sl:education:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlEducation slEducation)
    {
        startPage();
        List<SlEducation> list = slEducationService.selectSlEducationList(slEducation);
        return getDataTable(list);
    }

    /**
     * 导出学历列表
     */
    @PreAuthorize("@ss.hasPermi('sl:education:export')")
    @Log(title = "学历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlEducation slEducation)
    {
        List<SlEducation> list = slEducationService.selectSlEducationList(slEducation);
        ExcelUtil<SlEducation> util = new ExcelUtil<SlEducation>(SlEducation.class);
        util.exportExcel(response, list, "学历数据");
    }

    /**
     * 获取学历详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:education:query')")
    @GetMapping(value = "/{educationId}")
    public AjaxResult getInfo(@PathVariable("educationId") Long educationId)
    {
        return success(slEducationService.selectSlEducationByEducationId(educationId));
    }

    /**
     * 新增学历
     */
    @PreAuthorize("@ss.hasPermi('sl:education:add')")
    @Log(title = "学历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlEducation slEducation)
    {
        slEducation.setCreateBy(getUsername());
        return toAjax(slEducationService.insertSlEducation(slEducation));
    }

    /**
     * 修改学历
     */
    @PreAuthorize("@ss.hasPermi('sl:education:edit')")
    @Log(title = "学历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlEducation slEducation)
    {
        slEducation.setUpdateBy(getUsername());
        return toAjax(slEducationService.updateSlEducation(slEducation));
    }

    /**
     * 删除学历
     */
    @PreAuthorize("@ss.hasPermi('sl:education:remove')")
    @Log(title = "学历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{educationIds}")
    public AjaxResult remove(@PathVariable Long[] educationIds)
    {
        return toAjax(slEducationService.deleteSlEducationByEducationIds(educationIds));
    }
}
